<?php
// +----------------------------------------------------------------------
// | KITEGO-Admin「开箱即用」「人人全栈」
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.kitego.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed KITEGO并不是自由软件，未经许可不能去掉KITEGO相关版权
// +----------------------------------------------------------------------
// | Author: KITEGO Team <bd@kitego.cn>
// +----------------------------------------------------------------------

namespace oauth;

use oauth\enum\OAuthEnum;
use oauth\impl\GiteeImpl;

class OAuthProvider
{
    protected $strategy;

    public function __construct($authType)
    {
        $config = $this->getConfig($authType);

        $this->strategy = match ($authType) {
            OAuthEnum::GITEE => new GiteeImpl($config),
            default => exception('未知授权类型'),
        };
    }

    public function getStrategy()
    {
        return $this->strategy;
    }

    public function getConfig($authType)
    {
        $oauthConfig = sys_config('oauth');
        if (empty($oauthConfig)) exception('三方登录授权地址异常');

        return match ($authType) {
            OAuthEnum::GITEE => [
                'clientId' => $oauthConfig['giteeClientId'],
                'clientSecret' => $oauthConfig['giteeClientSecret'],
                'redirectUri' => $oauthConfig['giteeRedirectUrl'],
            ],
        };
    }
}